// pages/home/inquire/productDetails/productDetails.js
var util = require('../../../../utils/util.js')
var app = getApp();
var inquireScanCode = null;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hiddenDataView: true,
    hiddenLoading: true
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },
  goBack() {
    wx.navigateBack({

    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this
    this.setData({
      hiddenLoading: false
    });
    util.getRequest('shelf/productInfo/' + app.globalData.inquireScanCode + '/true', '', 'GET', function(result) {
        if (typeof(result) != 'undefined' && result != null) {
          if (!result.success) {
            that.setData({
              hiddenDataView: true,
              hiddenLoading: true
            })
            if (typeof(result.message) != 'undefined' && result.message != null && result.message != '') {
              that.showPrompt(result.message);
            } else {
              that.showPrompt('查询失败');
            }
          } else {
            var shelfs = result.data.shelfs;
            that.setData({
              hiddenDataView: false,
              hiddenLoading: true,
              imageUrl: result.data.pictureUrl,
              productTitle: result.data.productName,
              productNumber: result.data.itemNumber,
              productQuantity: result.data.qty,
              shelfs: shelfs
            })
          }
        } else {
          that.showPrompt('查询失败');
        }
      },
      function(failedResult) {
        console.log('failedResult');
        if (failedResult.data != undefined && failedResult.data != null) {
          that.showPrompt(failedResult.data.message);
        }
      });
  },

  showPrompt(content) {
    wx.showToast({
      title: content,
      icon: 'none',
      duration: 1300
    })
    setTimeout(function() {
      wx.navigateBack()
    }, 1300)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})